10 ' conway04.bas - FreeWare 2005
20 GOTO 60 ' begin
30 SAVE "conway04.bas",A:LIST-60
40 GOTO 530 ' wait for key
50 GOTO 560 ' centered text
60 SCREEN 9:CLS
70 DEFINT A-Q,S-Z:DEFSTR M,Q:Q=MKI$(0)
80 SH=60:SV=50:K=0:KMAX=150
90 WINDOW (2*SH-320,2*SV-240)-(2*SH+319,2*SV+239)
100 M(1)="CONWAY idea from Hans Lauwerier"
110 M(2)="GW-BASIC by Eric Tchong"
120 M(3)="This program shows 150 generations"
130 M(4)="Press a key to start"
140 FOR I=1 TO 4
150  GOSUB 50:IF I=3 THEN PRINT
160 NEXT:GOSUB 40:CLS
170 LINE (-4,-3)-(4*SH+4,4*SV+3),9,B
180 DIM U(SH,SV),V(SH,SV)
190 ' begin design
200 DATA 0,3,0,4,1,3,1,4,11,2,11,3,11,4,12,1,12,5,13,0
210 DATA 13,6,14,1,14,5,15,2,15,3,15,4,16,2,16,3,16,4
220 DATA 21,4,21,5,21,6,22,3,22,4,22,6,22,7,23,3,23,4
230 DATA 23,6,23,7,24,3,24,4,24,6,24,7,25,2,25,3,25,7
240 DATA 25,8,26,5,30,2,30,3,34,4,34,5,35,4,35,5
250 FOR I=1 TO 45
260  READ X,Y:X=X+3:Y=Y+36:U(X,Y)=1
270  LINE (4*X-1,4*Y-1)-(4*X+1,4*Y+1),10,BF
280 NEXT
290 ' main
300 WHILE K<=KMAX AND INKEY$=""
310  LOCATE 1,1:PRINT K
320  FOR I=1 TO SH-1
330   FOR J=1 TO SV-1
340    S0=U(I,J):V(I,J)=S0
350    S1=U(I-1,J-1)+U(I,J-1)+U(I+1,J-1)
360    S2=U(I-1,J)+U(I+1,J)
370    S3=U(I-1,J+1)+U(I,J+1)+U(I+1,J+1)
380    S=S1+S2+S3
390    IF S0=1 THEN IF S>3 OR S<2 THEN LINE (4*I-1,4*J-1)-(4*I+1,4*J+1),0,BF:V(I,J)=0
400    IF S0=0 AND S=3 THEN LINE (4*I-1,4*J-1)-(4*I+1,4*J+1),10,BF:V(I,J)=1
410   NEXT
420  NEXT
430 ' reset
440  FOR I=1 TO SH-1
450   FOR J=1 TO SV-1
460    U(I,J)=V(I,J)
470    IF U(I,J)=1 THEN LINE (4*I-1,4*J-1)-(4*I+1,4*J+1),10,BF
480   NEXT
490  NEXT:K=K+1
500 WEND:GOSUB 40
510 SCREEN 0,0,0:CLS:END
520 ' wait for key
530 LSET Q=MKI$(0)
540 WHILE CVI(Q)=0:MID$(Q,1)=INKEY$:WEND:RETURN
550 ' centered text
560 X=(80-LEN(M(I)))/2:PRINT TAB(X) M(I):RETURN
